package message.handler;

import java.util.Collection;

import message.StatusNotification;
import net.VirtualQueue;

import comunity.Community;
import comunity.Status;

public class StatusHandler implements Runnable {

	String owner;
	Status status;

	public StatusHandler(String owner, Status status) {
		this.owner = owner;
		this.status = status;
	}

	@Override
	public void run() {
		Community community = Community.obtainCommunity();
		VirtualQueue virtualQueue = VirtualQueue.obtainVirtualQueue();

		Collection<String> usernames = community.getOnlineUsers();
		for (String currentUsername : usernames) {
			if (currentUsername.equals(owner))
				continue;
			int port = 0;//community.getUserInputPort(currentUsername);
			double lat = community.getUserGPSLocation(currentUsername).getLat();
			double lon = community.getUserGPSLocation(currentUsername).getLon();
			Status ownerStatus = community.getUserStatus(owner);
			
			StatusNotification sn = new StatusNotification(currentUsername,
					owner, ownerStatus.toString(), port, lat, lon);
			virtualQueue.pushLowPriorityMessage(sn);
		}
	}
}
